package com.srv.common;

import java.util.HashMap;
import java.util.Map;

import com.srv.util.ObjectField;
import com.srv.util.ObjectFieldDBType;
import com.srv.util.StringUtil;

public class NodeField implements ObjectField{
	
	private static Map<String, NodeField> map = new HashMap<String, NodeField>();
	
	public static final NodeField PID = new NodeField("PID", ObjectFieldDBType.LONG, false, false);
	public static final NodeField ISDEL = new NodeField("ISDEL", ObjectFieldDBType.INT, true, false);
	public static final NodeField CREATETIME = new NodeField("CREATE_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	public static final NodeField UPDATETIME = new NodeField("UPDATE_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	public static final NodeField FAVORNUM = new NodeField("FAVOR_NUM", ObjectFieldDBType.LONG, true, false);
	public static final NodeField DOWNLOADNUM = new NodeField("DOWNLOAD_NUM", ObjectFieldDBType.LONG, true, false);
	public static final NodeField REPUBNUM = new NodeField("REPUB_NUM", ObjectFieldDBType.LONG, true, false);
	public static final NodeField TRAVEL_ID = new NodeField("TRAVEL_ID", ObjectFieldDBType.STRING, false, false);
	public static final NodeField NODE_ID = new NodeField("NODE_ID", ObjectFieldDBType.STRING, false, true);
	public static final NodeField IMG_URI = new NodeField("IMG_URI", ObjectFieldDBType.STRING, true, false);
	public static final NodeField RECORD_URI = new NodeField("RECORD_URI", ObjectFieldDBType.STRING, true, false);
	
	public static final NodeField IMG_INNER_URI = new NodeField("IMG_INNER_URI", ObjectFieldDBType.STRING, true, false);
	public static final NodeField RECORD_INNER_URI = new NodeField("RECORD_INNER_URI", ObjectFieldDBType.STRING, true, false);
	public static final NodeField CONTEXT = new NodeField("CONTEXT", ObjectFieldDBType.STRING, true, false);
	public static final NodeField TAG = new NodeField("TAG", ObjectFieldDBType.STRING, true, false);
	public static final NodeField LONGITUDE = new NodeField("LONGITUDE", ObjectFieldDBType.DOUBLE, true, false);
	public static final NodeField LATITUDE = new NodeField("LATITUDE", ObjectFieldDBType.DOUBLE, true, false);
	
	
	
	
	private String column;
    private ObjectFieldDBType type;
    private boolean modify = false;
    private boolean uniquene = false;
    
    public NodeField(String cn, ObjectFieldDBType type, boolean modify, boolean uniquene) {
    	this.column = cn;
        this.type = type;
        this.modify = modify;
        this.uniquene = uniquene;

        map.put(this.column, this);
    }
    
    public String getColumn() {
        return column;
    }

    public ObjectFieldDBType getType() {
        return type;
    }

    public boolean isModify() {
        return modify;
    }

    public boolean isUniquene() {
        return uniquene;
    }

    public int hashCode() {
        return column.hashCode();
    }
    
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof NodeField)) {
            return false;
        }

        return column.equalsIgnoreCase(((NodeField) obj).getColumn());
    }
    
    public static NodeField getByCode(String c) {
        if (StringUtil.isEmpty(c)) {
            return null;
        }

        return map.get(c.toLowerCase());
    }
}
